package com.miyuan.wm.controller;

import com.alibaba.fastjson.JSON;
import com.miyuan.wm.request.AddSuppliersRequestVo;
import com.miyuan.wm.request.QuerySuppliersRequestVo;
import com.miyuan.wm.request.UpdateSuppliersRequestVo;
import com.miyuan.wm.response.BaseResponse;
import com.miyuan.wm.response.PageResponse;
import com.miyuan.wm.response.QuerySupplierByIdResponseVo;
import com.miyuan.wm.response.QuerySuppliersResponseVo;
import com.miyuan.wm.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName SupplierController
 * @Description 供应商管理控制器
 */
@RestController
@Api(description = "供应商管理控制器", tags = {"供应商管理"})
@RequestMapping(value = "/supplier")
@Slf4j
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @ApiOperation(value = "获取供应商列表接口")
    @PostMapping("/querySuppliers")
    public PageResponse<List<QuerySuppliersResponseVo>> listSuppliers(@Valid @RequestBody QuerySuppliersRequestVo requestVo) {
        log.info("获取供应商列表接口请求参数：{}", JSON.toJSONString(requestVo));
        return supplierService.listSuppliers(requestVo);
    }

    @ApiOperation(value = "新增供应商信息接口")
    @PostMapping("/addSuppliers")
    public BaseResponse<Boolean> addSuppliers(@Valid @RequestBody AddSuppliersRequestVo requestVo) {
        log.info("新增供应商信息接口请求参数：{}", JSON.toJSONString(requestVo));
        return supplierService.addSuppliers(requestVo);
    }

    @ApiOperation(value = "修改供应商信息接口")
    @PostMapping("/updateSuppliers")
    public BaseResponse<Boolean> updateSuppliers(@Valid @RequestBody UpdateSuppliersRequestVo requestVo) {
        log.info("修改供应商信息接口请求参数：{}", JSON.toJSONString(requestVo));
        return supplierService.updateSuppliers(requestVo);
    }

    @ApiOperation(value = "删除供应商信息接口")
    @PostMapping("/deleteSuppliers")
    public BaseResponse<Boolean> deleteSuppliers(@RequestBody List<Integer> ids) {
        log.info("删除供应商信息接口请求参数：{}", JSON.toJSONString(ids));
        return supplierService.deleteSuppliers(ids);
    }

    @ApiOperation(value = "查询供应商信息，供下拉框使用")
    @GetMapping("/querySuppliersforSelect")
    public BaseResponse<List<QuerySuppliersResponseVo>> querySuppliersForSelect() {
        return supplierService.querySuppliersForSelect();
    }

    @ApiOperation(value = "根据Id查询供应商信息")
    @GetMapping("/querySupplierById")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "供应商数据库Id")})
    public BaseResponse<QuerySupplierByIdResponseVo> querySupplierById(@RequestParam int id) {
        return supplierService.querySupplierById(id);
    }


}
